﻿<cfcomponent output="false" displayName="xiErrorManager" hint="This is the global XI component for XI Errors.">

	<!--- initialization method --->
	<cffunction name="init" access="public" returnType="xiErrorManager" output="false">
		<cfreturn this>
	</cffunction>

	<!--- get XI error message method --->
	<cffunction name="error_messages_get" access="public" returntype="any" hint="Used to get the XI error message.">
		<cfargument name="error_code" type="string" required="yes">
		<cfquery name="get_error_messages" datasource="#application.dsn#">
			asp_get_error_messages
			@ierror_code='#arguments.error_code#'
		</cfquery>
		<cfif get_error_messages.recordcount gt 0>
			<cfset message_return=get_error_messages.english_language_message>
		<cfelse>
			<cfset message_return=''>
		</cfif>
		<cfreturn message_return>
	</cffunction>


	<!--- xi error method --->
	<cffunction name="xi_error" access="public" returntype="any" hint="Used to process XI errors.">
		<cfargument name="actioncode" type="string" required="yes">
		<cfargument name="actionmessage" type="string" required="yes">
			
			<!--- process actioncode --->
			<cfset var.count = Len(arguments.actioncode) - find(".", arguments.actioncode)>
			<cfif var.count gt 0>
				<cfset var.errorcode = right(arguments.actioncode, var.count)>
			<cfelse>
				<cfset var.errorcode = arguments.actioncode>
			</cfif>
			
			<!--- get error message --->
			<cfset error_message=error_messages_get(var.errorcode)>
			
			<!--- decide which error to reutrn --->
			<cfif Len(Trim(error_message)) NEQ 0>
				<cfset xi_error_response=error_message>
			<cfelse>
				<cfset xi_error_response=arguments.actionmessage>
			</cfif>
			
		<cfreturn xi_error_response>
	</cffunction>

</cfcomponent>